import requests
import parsel
headers={
 'user-agent': 'Mozilla/5.e (Windons NI 18.8; Winb4;x54)AppleWebkit/537.36(KHIML,like Gecko) Chrome/113.0.0.8 Safari/537.36', 'x-requested-with': 'XMLiIttpHequest',

}

for page in range(1,3):
    print(f'=========正在爬取第{page}页============')
    url = f'https://www.hexuexiao.cn/meinv/guzhuang/list-{page}.html'
    response = requests.get(url=url, headers=headers)
    response.encoding = response.apparent_encoding
 #print(response.text) 
    selector = parsel.Selector(response.text)
    href_list = selector.xpath('//div[@class="waterfall_1box"]/dl/dd/a/@href').getall()
 #print(href_list)
    for href in href_list:
        href_date = requests.get(url=href,headers=headers).text

        selector_2 = parsel.Selector(href_date)
        img_url = selector_2.xpath('//a[@class="btn btn-default btn-xs"]/@href').get()#
        #print(img_url)
        img_date = requests.get(url=img_url,headers=headers).content
        file_name = img_url.split('/')[-2]
        print(file_name)
        #with open('img1\\'+file_name,mode='wb') as f:
            #f.write(img_date)
            #print('保存完成：', file_name)